package com.ruoyi.hualian.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hualian.domain.HlScrew;
import com.ruoyi.hualian.service.IHlScrewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 螺丝Controller
 * 
 * @author hujian
 */
@RestController
@RequestMapping("/hualian/screw")
public class HlScrewController extends BaseController
{
    @Autowired
    private IHlScrewService hlScrewService;

    /**
     * 查询螺丝列表
     */
    @PreAuthorize("@ss.hasPermi('hualian:screw:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlScrew hlScrew)
    {
        startPage();
        List<HlScrew> list = hlScrewService.selectHlScrewList(hlScrew);
        return getDataTable(list);
    }

    /**
     * 导出螺丝列表
     */
    @PreAuthorize("@ss.hasPermi('hualian:screw:export')")
    @Log(title = "螺丝", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HlScrew hlScrew)
    {
        List<HlScrew> list = hlScrewService.selectHlScrewList(hlScrew);
        ExcelUtil<HlScrew> util = new ExcelUtil<HlScrew>(HlScrew.class);
        util.exportExcel(response, list, "螺丝数据");
    }

    /**
     * 获取螺丝详细信息
     */
    @PreAuthorize("@ss.hasPermi('hualian:screw:query')")
    @GetMapping(value = "/{screwId}")
    public AjaxResult getInfo(@PathVariable("screwId") Long screwId)
    {
        return success(hlScrewService.selectHlScrewByScrewId(screwId));
    }

    /**
     * 新增螺丝
     */
    @PreAuthorize("@ss.hasPermi('hualian:screw:add')")
    @Log(title = "螺丝", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HlScrew hlScrew)
    {
        return toAjax(hlScrewService.insertHlScrew(hlScrew));
    }

    /**
     * 修改螺丝
     */
    @PreAuthorize("@ss.hasPermi('hualian:screw:edit')")
    @Log(title = "螺丝", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HlScrew hlScrew)
    {
        return toAjax(hlScrewService.updateHlScrew(hlScrew));
    }

    /**
     * 删除螺丝
     */
    @PreAuthorize("@ss.hasPermi('hualian:screw:remove')")
    @Log(title = "螺丝", businessType = BusinessType.DELETE)
	@DeleteMapping("/{screwIds}")
    public AjaxResult remove(@PathVariable Long[] screwIds)
    {
        return toAjax(hlScrewService.deleteHlScrewByScrewIds(screwIds));
    }
}
